package com.bytezero.login_test.home;

import com.bytezero.login_test.bean.BaseBean;
import com.bytezero.login_test.bean.Goods;
import com.bytezero.login_test.network.RetrofitClient;
import com.bytezero.login_test.service.GoodsService;

import org.reactivestreams.Subscriber;

import java.util.List;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.core.Scheduler;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.schedulers.Schedulers;

/**
 * @author Bytezero_zhenglei!
 * @package com.bytezero.login_test.home
 * @fileName
 * @data 2022/1/28 16:30
 * @description
 * @TODO
 * @email 420498246@qq.com
 */
public class HomePresenter implements HomeContract.IHomePresenter {
    private final HomeContract.IHomeView homeView;
    private HomeContract.IHomeModel homeModel;

    public HomePresenter(HomeContract.IHomeView homeView) {
        this.homeView = homeView;
        homeModel = new HomeModel();

    }

    @Override
    public void getData() {
        homeModel.getData()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<BaseBean<List<Goods>>>() {
                    @Override
                    public void accept(BaseBean<List<Goods>> listBaseBean) throws Throwable {
                        homeView.getGoodsSucess(listBaseBean.getData());

                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Throwable {
                       homeView.getGoodsError(throwable);
                    }
                });
    }
}


